//
//  JPNavigationController.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/4/19.
//

#import "JPNavigationController.h"
#import "BaseViewController.h"

@interface JPNavigationController ()<UINavigationControllerDelegate>
@property (nonatomic, getter=isPushing) BOOL pushing;
@end

@implementation JPNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self createUI];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.pushing == YES) {
       NSLog(@"被拦截");
       return;
    } else {
       NSLog(@"push");
       self.pushing = YES;
    }
    if (self.viewControllers.count){
        viewController.hidesBottomBarWhenPushed = YES;
        if ([viewController isKindOfClass:[BaseViewController class]]){
            [(BaseViewController *)viewController defaultBackSet];
        }
    }
    [super pushViewController:viewController animated:animated];
}


#pragma mark - 界面配置修改
-(void)createUI{
    self.navigationBarHidden = YES;
    [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsCompact];
    [self.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsCompact];

    self.navigationBar.backIndicatorTransitionMaskImage = [UIImage new];

    self.automaticallyAdjustsScrollViewInsets = NO;
    
}

#pragma mark - UINavigationControllerDelegate
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    self.pushing = NO;
}

- (UIViewController *)popViewControllerAnimated:(BOOL)animated{
    return [super popViewControllerAnimated:animated];
}

- (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated{
    return [super popToRootViewControllerAnimated:animated];
}


+ (void)initialize{
    UINavigationBar *bar = [UINavigationBar appearance];
    [bar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [bar setShadowImage:[UIImage new]];
}


@end
